﻿using System;
using System.Collections.Generic;

namespace GeneticAlgorithm.Interfaces
{
    /// <summary>
    /// 可进化的对象
    /// </summary>
    /// <typeparam name="T">基因所携带遗传信息的类型</typeparam>
    public interface IEvolvable<T>
    {
        /// <summary>
        /// 基因序列
        /// </summary>
        List<Gene<T>> GeneSequence { get; set; }

        /// <summary>
        /// 解析基因序列
        /// </summary>
        /// <param name="parameter">携带基因序列信息的参数</param>
        void ParseGeneSequence(object parameter);

        /// <summary>
        /// 适应度
        /// </summary>
        double Fitness { get; set; }

        /// <summary>
        /// 获取指定范围内的基因序列
        /// </summary>
        /// <param name="index">序列起点</param>
        /// <param name="count">序列长度</param>
        List<Gene<T>> GetGeneSequenceRange(int index, int count)
        {
            if (index >= 0 && count >= 0 && index + count <= GeneSequence.Count)
                return GeneSequence.GetRange(index, count);
            else
                throw new ArgumentOutOfRangeException("超出基因序列索引范围");
        }
    }
}
